package pchi.pchicamera;

import pchi.pchicamera.adapters.TabsAdapter;
import pchi.pchicamera.fragmenttabs.TabEdittor;
import pchi.pchicamera.fragmenttabs.TabEdittor.OnTabImagesPreviewSelectedListener;
import pchi.pchicamera.fragmenttabs.TabImagesPreview;
import android.app.ActionBar;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.widget.Toast;

public class EdittingImagesActivity extends FragmentActivity implements
		OnTabImagesPreviewSelectedListener {

	ViewPager mViewPager;
	TabsAdapter mTabsAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		// requestWindowFeature(Window.FEATURE_NO_TITLE);
		mViewPager = new ViewPager(this);
		mViewPager.setId(R.id.pager);
		setContentView(mViewPager);

		final ActionBar bar = getActionBar();
		bar.setDisplayShowTitleEnabled(false);
		bar.setDisplayShowHomeEnabled(false);
		bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

		bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

		mTabsAdapter = new TabsAdapter(this, mViewPager);

		mTabsAdapter.addTab(bar.newTab().setText("Image Preview"),
				TabImagesPreview.class, null);

		mTabsAdapter.addTab(bar.newTab().setText("Editor"), TabEdittor.class,
				null);

		if (savedInstanceState != null) {
			bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
		}

	}

	@Override
	public void OnTabImagesPreviewSelected(int position) {
		TabImagesPreview tabImagesPreview = (TabImagesPreview) getSupportFragmentManager()
				.findFragmentByTag(
						Apps.getTagOfFragment().getTagOfTabImagesPreview());

		if (tabImagesPreview != null) {
			Toast.makeText(getApplicationContext(), "Sucess",
					Toast.LENGTH_SHORT).show();
			tabImagesPreview.updateView(position);
		} else {
			try {
				Toast.makeText(getApplicationContext(), "tabFragment was null",
						Toast.LENGTH_SHORT).show();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

}
